home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / ds3100.md / signals.c < prev    next >
C/C++ Source or Header  |  1991-07-26  |  7KB  |  291 lines

  1. /* 
  2.  * signals.c --
  3.  *
  4.  *    Procedure to map from Unix signal system calls to Sprite.
  5.  *
  6.  *
  7.  * Copyright (C) 1986 Regents of the University of California
  8.  * All rights reserved.
  9.  */
  10.  
  11. #ifndef lint
  12. static char rcsid[] = "$Header: /sprite/src/kernel/mach/ds3100.md/RCS/signals.c,v 9.2 91/07/26 17:02:35 shirriff Exp $ SPRITE (Berkeley)";
  13. #endif not lint
  14.  
  15. #include "sprite.h"
  16. #include "sig.h"
  17. #include "status.h"
  18.  
  19. #include "compatInt.h"
  20. #include "user/sys/signal.h"
  21. #include "machInt.h"
  22. #include "mach.h"
  23. #include "machConst.h"
  24.  
  25. extern Mach_State    *machCurStatePtr;
  26.  
  27.  
  28. /*
  29.  *----------------------------------------------------------------------
  30.  *
  31.  * sigvec --
  32.  *
  33.  *    Procedure to map from Unix sigvec system call to Sprite Sig_SetAction.
  34.  *
  35.  * Results:
  36.  *    Error code is returned upon error.  Otherwise SUCCESS is returned.
  37.  *
  38.  * Side effects:
  39.  *    The signal handler associated with the specified signal is modified.
  40.  *
  41.  *----------------------------------------------------------------------
  42.  */
  43. ReturnStatus
  44. MachUNIXSigvec(sig, newVectorPtr, oldVectorPtr)
  45.     int         sig;        /* Signal to set the vector for. */
  46.     struct sigvec    *newVectorPtr;    /* New vector. */
  47.     struct sigvec    *oldVectorPtr;    /* Old vector. */
  48. {
  49.     int         spriteSignal;    /* Equivalent signal for Sprite */
  50.     Sig_Action         newAction;    /* Action to take */
  51.     Sig_Action        *newActionPtr;
  52.     Sig_Action         oldAction;    /* Former action */
  53.     Sig_Action        *oldActionPtr;
  54.     ReturnStatus     status;        /* Generic result code */
  55.     Address        usp;
  56.     struct sigvec newVector;
  57.     struct sigvec oldVector;
  58.  
  59.     usp = (Address)machCurStatePtr->userState.regState.regs[SP];
  60.     newActionPtr = (Sig_Action *)(usp - sizeof(Sig_Action));
  61.     oldActionPtr = (Sig_Action *)(usp - 2 * sizeof(Sig_Action));
  62.  
  63.     status = Compat_UnixSignalToSprite(sig, &spriteSignal);
  64.     if (status == FAILURE || spriteSignal == NULL) {
  65.     return(SYS_INVALID_ARG);
  66.     }
  67.  
  68.     if (newVectorPtr != (struct sigvec *)NULL) {
  69.     status = Vm_CopyIn(sizeof(struct sigvec), (Address)newVectorPtr,
  70.                (Address)&newVector);
  71.     if (status != SUCCESS) {
  72.         return(status);
  73.     }
  74.     switch ((int)newVector.sv_handler) {
  75.         case SIG_DFL:
  76.         newAction.action = SIG_DEFAULT_ACTION;
  77.         break;
  78.         case SIG_IGN:
  79.         newAction.action = SIG_IGNORE_ACTION;
  80.         break;
  81.         default:
  82.         newAction.action = SIG_HANDLE_ACTION;
  83.         newAction.handler = (int(*)())newVector.sv_handler;
  84.     }
  85.     status = Compat_UnixSigMaskToSprite(newVector.sv_mask,
  86.                         &newAction.sigHoldMask);
  87.     if (status == FAILURE) {
  88.         return(SYS_INVALID_ARG);
  89.     }
  90.  
  91.     status = Vm_CopyOut(sizeof(Sig_Action), (Address)&newAction,
  92.                 (Address)newActionPtr);
  93.     if (status != SUCCESS) {
  94.         return(status);
  95.     }
  96.     status = Sig_SetAction(spriteSignal, newActionPtr, oldActionPtr);
  97.     if (status != SUCCESS) {
  98.         return(status);
  99.     } 
  100.     }
  101.  
  102.     if (oldVectorPtr != NULL) {
  103.     (void)Vm_CopyIn(sizeof(Sig_Action), (Address)oldActionPtr, 
  104.             (Address)&oldAction);
  105.     switch (oldAction.action) {
  106.         case SIG_DEFAULT_ACTION:
  107.         oldVector.sv_handler = SIG_DFL;
  108.         break;
  109.         case SIG_IGNORE_ACTION:
  110.         oldVector.sv_handler = SIG_IGN;
  111.         break;
  112.         default:
  113.         oldVector.sv_handler = (void(*)())oldActionPtr->handler;
  114.         break;
  115.     }
  116.     (void) Compat_SpriteSigMaskToUnix(oldAction.sigHoldMask, 
  117.                       &oldVector.sv_mask);
  118.     oldVector.sv_flags = 0;
  119.     status = Vm_CopyOut(sizeof(oldVector), (Address)&oldVector,
  120.                 (Address)oldVectorPtr);
  121.     if (status != SUCCESS) {
  122.         return(status);
  123.     }
  124.     }
  125.  
  126.     return(SUCCESS);
  127. }
  128.  
  129.  
  130. /*
  131.  *----------------------------------------------------------------------
  132.  *
  133.  * sigblock --
  134.  *
  135.  *    Procedure to map from Unix sigblock system call to Sprite 
  136.  *    Sig_SetHoldMask.
  137.  *
  138.  * Results:
  139.  *    Error code is returned upon error.  Otherwise SUCCESS is returned.
  140.  *
  141.  * Side effects:
  142.  *    The current signal mask is modified.
  143.  *
  144.  *----------------------------------------------------------------------
  145.  */
  146.  
  147. ReturnStatus
  148. MachUNIXBlock(mask)
  149.     int mask;            /* additional bits to mask */
  150. {
  151.     int spriteMask = 0;        /* equivalent mask for Sprite */
  152.     int oldSpriteMask;        /* old mask, in Sprite terms */
  153.     ReturnStatus status;    /* generic result code */
  154.  
  155.     status = Compat_UnixSigMaskToSprite(mask,&spriteMask);
  156.     if (status == FAILURE) {
  157.     return(SYS_INVALID_ARG);
  158.     }
  159.     status = Compat_GetSigHoldMask(&oldSpriteMask);
  160.     if (status == FAILURE) {
  161.     return(SYS_INVALID_ARG);
  162.     }
  163.     status = Sig_SetHoldMask(spriteMask | oldSpriteMask, (int *) NULL);
  164.     if (status != SUCCESS) {
  165.     return(status);
  166.     } else {
  167.     status = Compat_SpriteSigMaskToUnix(oldSpriteMask, 
  168.                     &machCurStatePtr->userState.unixRetVal);
  169.     if (status == FAILURE) {
  170.         return(SYS_INVALID_ARG);
  171.     }
  172.     return(SUCCESS);
  173.     }
  174. }
  175.  
  176.  
  177.  
  178. /*
  179.  *----------------------------------------------------------------------
  180.  *
  181.  * sigsetmask --
  182.  *
  183.  *    Procedure to map from Unix sigsetmask system call to Sprite 
  184.  *    Sig_SetHoldMask.
  185.  *
  186.  * Results:
  187.  *    Error code is returned upon error.  Otherwise SUCCESS is returned.
  188.  *
  189.  * Side effects:
  190.  *    The current signal mask is modified.
  191.  *
  192.  *----------------------------------------------------------------------
  193.  */
  194. ReturnStatus
  195. MachUNIXSigSetmask(mask)
  196.     int mask;            /* new mask */
  197. {
  198.     int spriteMask = 0;        /* equivalent mask for Sprite */
  199.     int oldSpriteMask;        /* old mask, in Sprite terms */
  200.     ReturnStatus status;    /* generic result code */
  201.     Address usp;
  202.  
  203.     status = Compat_UnixSigMaskToSprite(mask,&spriteMask);
  204.     if (status == FAILURE) {
  205.     return(SYS_INVALID_ARG);
  206.     }
  207.     usp = (Address)(machCurStatePtr->userState.regState.regs[SP] - 4);
  208.     status = Sig_SetHoldMask(spriteMask, (int *)usp);
  209.     if (status != SUCCESS) {
  210.     return(status);
  211.     } else {
  212.     (void)Vm_CopyIn(sizeof(oldSpriteMask), usp, (Address)&oldSpriteMask);
  213.     status = Compat_SpriteSigMaskToUnix(oldSpriteMask,
  214.                     &machCurStatePtr->userState.unixRetVal);
  215.     if (status == FAILURE) {
  216.         return(SYS_INVALID_ARG);
  217.     }
  218.     return(SUCCESS);
  219.     }
  220. }
  221.  
  222.  
  223.  
  224. /*
  225.  *----------------------------------------------------------------------
  226.  *
  227.  * sigpause --
  228.  *
  229.  *    Procedure to map from Unix sigsetmask system call to Sprite 
  230.  *    Sig_SetHoldMask.
  231.  *
  232.  * Results:
  233.  *    Error code is returned upon error.  Otherwise SUCCESS is returned.
  234.  *
  235.  * Side effects:
  236.  *    The current signal mask is modified.
  237.  *
  238.  *----------------------------------------------------------------------
  239.  */
  240.  
  241. ReturnStatus
  242. MachUNIXSigPause(mask)
  243.     int mask;            /* new mask */
  244. {
  245.     int spriteMask = 0;        /* equivalent mask for Sprite */
  246.     ReturnStatus status;    /* generic result code */
  247.  
  248.     status = Compat_UnixSigMaskToSprite(mask,&spriteMask);
  249.     if (status == FAILURE) {
  250.     return(SYS_INVALID_ARG);
  251.     }
  252.     status = Sig_Pause(spriteMask);
  253.     if (status != SUCCESS) {
  254.     return(status);
  255.     } else {
  256.     return(GEN_ABORTED_BY_SIGNAL);
  257.     }
  258. }
  259.  
  260.  
  261. /*
  262.  *----------------------------------------------------------------------
  263.  *
  264.  * sigstack --
  265.  *
  266.  *    Procedure to fake the Unix sigstack system call.
  267.  *
  268.  * Results:
  269.  *    Error code is returned upon error.  Otherwise SUCCESS is returned.
  270.  *
  271.  * Side effects:
  272.  *    None.
  273.  *
  274.  *----------------------------------------------------------------------
  275.  */
  276. /*ARGSUSED*/
  277. ReturnStatus
  278. MachUNIXSigStack(ss, oss)
  279.     struct sigstack *ss, *oss;
  280. {
  281.     struct sigstack oldStack;
  282.     if (oss != NULL) {
  283.     oldStack.ss_sp = 0;
  284.     oldStack.ss_onstack = 0;
  285.     return(Vm_CopyOut(sizeof(struct sigstack), (Address)&oldStack,
  286.               (Address)oss));
  287.     }
  288.     return(SUCCESS);
  289. }
  290.  
  291.